package shiyan3;

import java.util.HashSet;
import java.util.Set;

public class SetExample {
	public static void main(String[] args) {
		//1.创建HashSet并添加元素
		Set<Integer>set=new HashSet<>();
		set.add(1);
		set.add(2);
		set.add(3);
		set.add(2);//重复元素
		
		//2.遍历HashSet
		System.out.println("Elements in the set:");
		for(Integer element:set) {
			System.out.println(element);
		}
		
		//3.判断元素是否存在
		boolean containsTwo=set.contains(2);
		System.out.println("\nSet contains 2:"+containsTwo);
	}
}
